import {getStyle} from '../utils/mUtil'
export const loadMoreMixin={
    directives: {
        "load-more": {
            bind:function(el,binding){
                let windowHeight=document.body.clientHeight ||document.documentElement.clientHeight;
                let height;// el 高度
                let requestFram;
                let oldScrollTop;
                let heightEl = el;
                el.addEventListener('touchstart',function(event){
                    height=heightEl.clientHeight;
                },false);
                el.addEventListener('touchmove',function(event){
                    loadMore();
                },false)
                el.addEventListener('touchend',function(event){
                    oldScrollTop = document.documentElement.scrollTop||document.body.scrollTop;
                    moveEnd();
                },false);
                const moveEnd = ()=>{
                    // requestAnimationFrame 是 H5 请求动画帧
                    requestFram = requestAnimationFrame(()=>{
                        let newScrollTop=document.documentElement.scrollTop||document.body.scrollTop;
                        if(newScrollTop != oldScrollTop){
                            oldScrollTop=newScrollTop
                            moveEnd();
                        }else{
                            cancelAnimationFrame(requestFram);
                            height = heightEl.clientHeight;
                            loadMore();
                        }
                    })
                }
                const loadMore=()=>{
                    let newScrollTop=document.documentElement.scrollTop||document.body.scrollTop;
                    if(newScrollTop + windowHeight > height +130){
                        binding.value();
                    }
                }
            },
        }
    }
}
export const getImgPathMixin = {
    methods:{
        getImgPath(path){
            let suffix;
			if (!path) {
				return '//cangdu.org:8001/img/default.jpg'
            }
            if (path.indexOf('jpeg') !== -1) {
				suffix = '.jpeg'
			} else {
				suffix = '.png'
            }
            let url = '/'+path.substr(0,1)+ '/' + path.substr(1, 2) + '/' + path.substr(3) + suffix;
            return 'https://fuss10.elemecdn.com' + url
        }
    }
}